<script type="text/javascript">
	//<![CDATA[
	function get_log(cbi_id) {
		if (cbi_id) {
			XHR.get('<%=url([[admin]], [[services]], [[passwall]], [[server_user_log]])%>', {
					id: cbi_id
				},
				function(x, result) {
					if (x && x.status == 200) {
						if (result.code == 200) {
							var content = result.data;
							content = content.replace(/\n/g, "<br />");
							var new_window = window.open();
							new_window.document.write(content);
						} else {
							alert('<%:Not enabled log%>');
						}
					}
				}
			);
		}
	}
	
	var _users_status = document.getElementsByClassName('_users_status');
	for(var i = 0; i < _users_status.length; i++) {
		var id = _users_status[i].parentElement.parentElement.parentElement.id;
		id = id.substr(id.lastIndexOf("-") + 1);
		XHR.get('<%=url([[admin]], [[services]], [[passwall]], [[server_user_status]])%>', {
				index: i,
				id: id
			},
			function(x, result) {
				_users_status[result.index].setAttribute("style","font-weight:bold;");
				_users_status[result.index].setAttribute("color",result.status ? "green":"red");
				_users_status[result.index].innerHTML = (result.status ? '✓' : 'X');
			}
		);
	}
	
	var edit_btn = document.getElementById("cbi-passwall_server-user").getElementsByClassName("cbi-button cbi-button-edit");
	for (var i = 0; i < edit_btn.length; i++) {
		try {
			var onclick_str = edit_btn[i].getAttribute("onclick");
			var id = onclick_str.substring(onclick_str.lastIndexOf('/') + 1, onclick_str.length - 1);
			var td = edit_btn[i].parentNode;
			var new_div = "";
			//添加"日志"按钮
			new_div += '<input class="cbi-button cbi-button-add" type="button" value="<%:Log%>" onclick="get_log(\'' + id + '\')"/>&nbsp;&nbsp;';
			td.innerHTML = new_div + td.innerHTML;
		}
		catch(err) {
			console.error(err);
		}
	}
	//]]>
</script>